﻿/*
 * 由SharpDevelop创建。
 * 用户： Administrator
 * 日期: 2025/8/8
 * 时间: 11:27
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using System.IO;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using PMXRenderer;

namespace MVP
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		void Button1Click(object sender, EventArgs e)
		{
			
			
			string t="";
             
			string ml=textBox1.Text;
             string[] files = Directory.GetFiles(ml,"*.pmx", SearchOption.AllDirectories);
            
		    foreach (var file in files)
		    {
		    	string th=@"<tr>
						<td>$img$</td>
						<td>$modelname$</td>
						<td>$modeler$</td>
						<td>$filepath$</td>
					</tr>";
		    	try {
		    		var renderer = new PMXRenderer.PMXRenderer();
		    	    renderer.GeneratePmxPreview(file,600,800).Save(Directory.GetCurrentDirectory()+"\\img\\"+Path.GetFileNameWithoutExtension(file)+".png");
		    
		    	    th=th.Replace("$img$","<img src=\"../img/"+Path.GetFileNameWithoutExtension(file)+".png" +"\" width=200>");
		    	    th=th.Replace("$modelname$",Path.GetFileNameWithoutExtension(file));
		    	    th=th.Replace("$modeler$",file.Replace(ml,"").Split('\\')[1]);
		    	    th=th.Replace("$filepath$","<a href=\"file:///"+Path.GetDirectoryName(file)+"\">打开模型文件夹</a>");
		    	    
		    	 //  MessageBox.Show(th);
		    	    t+=th+"\n";
		    	} catch (Exception) {}
		    }
		    
		    string html=File.ReadAllText("html\\temp.html");
		    html=html.Replace("$line$",t);
		    File.WriteAllText("html\\index.html",html);
		    
		    System.Diagnostics.Process.Start("html\\index.html");
		}
 
	}
}
